/**
 * https://leetcode.cn/problems/remove-stones-to-minimize-the-total/submissions/590084683/
 * 1962.移除石子使总数最小
 * medium 2024.12.29
 * 优先队列
 */

class Solution {
public:
    int minStoneSum(vector<int>& piles, int k) {
        priority_queue<int> q;
        int sum=0;
        for(auto &x:piles){
            sum+=x;
            q.emplace(x);
        }
        while(k--){
            int x=q.top();
            q.pop();
            sum-=(x/2);
            q.emplace(x-(x/2));
        }
        return sum;
    }
};